import Tkinter #Python integrated tool kit for interfaces
import DOFCalc #import the depth of feild calculator
import FOVCalc #import feild of view calculator
import dslrFactory #import the dslr factory

class App:
    def __init__(self, master):
        # Define frame size and position in the screen :
        ScreenSizeX = master.winfo_screenwidth()  # Get screen width [pixels]
        ScreenSizeY = master.winfo_screenheight() # Get screen height [pixels]
        ScreenRatio = 0.8                              # Set the screen ratio for width and height
        FrameSizeX  = int(ScreenSizeX * ScreenRatio)
        FrameSizeY  = int(ScreenSizeY * ScreenRatio)
        FramePosX   = (ScreenSizeX - FrameSizeX)/2 # Find left and up border of window
        FramePosY   = (ScreenSizeY - FrameSizeY)/2
        master.geometry("%sx%s+%s+%s"%(FrameSizeX, FrameSizeY, FramePosX, FramePosY))
        frame = Tkinter.Frame(master)
        frame.pack()

        #place a header image

        photo = Tkinter.PhotoImage(file = 'ipaheader.gif')

        pic = Tkinter.Label(master, image= photo)
        pic.image = photo
        pic.pack()
        pic.place(x="300", y="0")

        # place a label with large text about the app
        labelHeadline = Tkinter.Label(master, text="Placeholder Softworks", font=("Myriad Pro", 25))
        labelHeadline.pack()
        labelHeadline.place(x="440", y="300")

        # place an instructional message down bellow
        instructLine = Tkinter.Label(master, text="Enter your information and then use our calculators. ", font=("Myriad Pro", 18))
        instructLine.pack()
        instructLine.place(x="380", y="350")

        # place some menu bars and text.
        bodyLine = Tkinter.Label(master, text="Camera Body", font=("Myriad Pro", 18))
        bodyLine.pack()
        bodyLine.place(x="40", y="380")

        curBody = Tkinter.StringVar()
        curBody.set("Canon EOS 5D Mark II") # initial value
        bodyOption = Tkinter.OptionMenu(master, curBody, "Canon EOS 5D Mark II", "Canon Rebel T1i", "Canon EOS-1D X", "Canon EOS 5D Mark III", "Canon EOS 6D", "Canon EOS 7D", "Canon EOS 60D", "Canon EOS 60Da", "Canon EOS 100D", "Canon EOS Rebel SL1", "Canon EOS Kiss X7", "Canon EOS 700D", "Canon EOS Rebel T5i", "Canon EOS 650D", "Canon EOS Rebel T4i", "Canon EOS Kiss X6i", "Canon EOS 600D", "Canon EOS Rebel T3i", "Canon EOS Kiss X5", "Canon EOS 1100D", "Canon EOS Rebel T3", "Canon EOS Kiss X50")
        bodyOption.pack()
        bodyOption.place(x="40", y="440")

        # place some menu bars and text.
        fStopLine = Tkinter.Label(master, text="Current fStop", font=("Myriad Pro", 18))
        fStopLine.pack()
        fStopLine.place(x="260", y="380")

        curFStop = Tkinter.StringVar()
        curFStop.set("11.0") # initial value
        fStopOption = Tkinter.OptionMenu(master, curFStop, "1.4", "2.0", "2.8", "4.0", "5.6", "8.0", "11.0", "16.0", "22.0")
        fStopOption.pack()
        fStopOption.place(x="260", y="440")


        # place some text areas and text.
        focalLine = Tkinter.Label(master, text="Enter Focal Length", font=("Myriad Pro", 18))
        focalLine.pack()
        focalLine.place(x="400", y="380")

        curFocal = Tkinter.StringVar()
        curFocal.set('50')
        focalText = Tkinter.Entry(master, textvariable = curFocal)
        focalText.pack()
        focalText.place(x="400", y="440")

        # place some menu text areas and text.
        distanceLine = Tkinter.Label(master, text="Enter Distance", font=("Myriad Pro", 18))
        distanceLine.pack()
        distanceLine.place(x="600", y="380")

        curDistance = Tkinter.StringVar()
        curDistance.set('6')
        disText = Tkinter.Entry(master, textvariable = curDistance)
        disText.pack()
        disText.place(x="600", y="440")

        curResult = Tkinter.StringVar()
        curResult.set("This is where the Results of the calculators will be placed")
        #this label will be used to disply the results of the calculators
        resultLine = Tkinter.Label(master, textvariable=curResult, font=("Myriad Pro", 22))
        resultLine.pack()
        resultLine.place(x="300", y="550")

        def getDOF():
            #this function will get the dof

            body = curBody.get()
            fStop = curFStop.get()
            focal = curFocal.get()
            dist = curDistance.get()

            yourCamera = dslrFactory.createDslr(body, "canon")
            coc = yourCamera.cOC


            curResult.set(DOFCalc.calculateDOF(yourCamera.cOC, focal, dist, fStop))

            #curResult.set("new DOF")

        def getFOV():

            body = curBody.get()

            focal = curFocal.get()
            dist = curDistance.get()

            yourCamera = dslrFactory.createDslr(body, "canon")
            curResult.set((FOVCalc.calculateRectFOV(yourCamera.sensorWidth, yourCamera.sensorHeight, focal, dist)))




        #these buttons will be used to call the calculators

        fovButton = Tkinter.Button(master, text="Calculate Field of View  ", command= getFOV)
        fovButton.pack()
        fovButton.place(x="820", y="380")

        dofButton = Tkinter.Button(master, text="Calculate Depth of Field", command= getDOF)
        dofButton.pack()
        dofButton.place(x="820", y="440")


        print "hello !"



if __name__ == "__main__":
    root = Tkinter.Tk()
    app = App(root)
    root.mainloop()

